package com.winit.deploy.service;

import com.alibaba.fastjson.JSONObject;
import com.winit.common.base.beans.LoginUser;
import com.winit.deploy.bean.DeployEnum;
import com.winit.deploy.manager.DeployManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 构建工程.
 *
 * Created by keel2008 on 16/9/27.
 */
@Component
public class DeployService {

    private static final Logger logger = LoggerFactory.getLogger(DeployService.class);

    @Resource
    private DeployManager deployManager;


    /**
     * 获取已经被置为测试通过(提交运维发版)的工程分支和版本信息.
     * @param projectName 主干工程名
     * @return
     * @throws Exception
     */
    public JSONObject getPassProjectAndEdition(String projectName) throws Exception{
        return deployManager.getPassProjectAndEdition(projectName);
    }

    /**
     *
     *
     * @param projectName
     * @param editionNum
     * @param status 0 不通过 1 通过 2 未测试  具体请参考Constants定义的 PROJECT_EDITION_TEST_STATUS_NOT_PASS 常量.
     * @return
     * @throws Exception
     */
    public boolean updateProjectTestPassEdition(String projectName, String editionNum, String status,LoginUser userInfo) throws Exception{
        return  deployManager.updateProjectTestPassEdition(projectName,editionNum,status,userInfo);
    }

    /**
     * 获取线上/staging工程名及版本号
     * @param trunkName
     * @param type
     * @return
     */
    public String getOnlineOrStagingVersion(String trunkName, DeployEnum deployEnum, String type){
        return deployManager.getOnlineOrStagingVersion(trunkName,deployEnum,type);
    }
}
